package com.lqjava.flowable.beans.result;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.ArrayList;
import java.util.List;
/**
 * Api统一响应格式
 * 返回分页对象
 * @param <T> 实体
 * @author lq 2021年3月21日 18:35:33
 */
public class PageResultBean <T> {

	private boolean success;
	
	private String msg;
	
	private Long total;
	
	private List<T> rows = new ArrayList<>();
	
	public PageResultBean(){
		this.success = true;
	}
	public Long getTotal() {
		return total;
	}
	public void setTotal(Long total) {
		this.total = total;
	}
	public List<T> getRows() {
		return rows;
	}
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	
	public void initTrue(List<T> rows,Long total){
		this.success = true;
		this.msg = "successful";
		this.rows = rows;
		this.total = total;
	}
	
	public void initFalse(String msg){
		this.success = false;
		this.msg = msg;
		this.total = 0l;
	}
	public void initTrue(PageResultBean<T> page) {
		this.success = true;
		this.msg = "successful";
		this.rows = page.getRows();
		this.total = page.getTotal();
	}
	public void initTrue(IPage<T> page) {
		this.success = true;
		this.msg = "successful";
		this.rows = page.getRecords();
		this.total = page.getTotal();
	}

}
